<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;

class SystemAttachment extends Model
{
    use HasFactory;
    use PimpableTrait;

    public $searchable = [
        'name',
        'category_id',
        'user_id',
        'att_dir',
        'size',
        "type",
        "pid",
        'hash',
        'upload_type',
        'module_type',
        'original_name'
    ];

    public $fillable = [
        'name',
        'category_id',
        'user_id',
        'att_dir',
        'satt_dir',
        'size',
        'type',
        'pid',
        'hash',
        'upload_type',
        'module_type',
        'original_name',
    ];

    public $sortable = [
        'size',
    ];

    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 附件所属分类
     */
    public function systemAttachmentCategory()
    {
        return $this->belongsTo(SystemAttachmentCategory::class, 'pid','id');
    }
}
